<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\reservation\model;

use app\project\model\project;
use plugin\saiadmin\basic\BaseNormalModel;
use app\cassification\model\ClassificationDictionary;
/**
 * 预约列表模型
 */
class reservation extends BaseNormalModel
{

    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'reservation_id';

    /**
     * 数据库表名称
     * @var string
     */
    protected $table = 'eb_reservation';

    protected $append = [
        'project_id_text',
        'status_text',
        'reservation_time_text',
         'rent_nature_text',
    ];
    /**
     * 预约项目标题 搜索
     */
    public function searchProjectIdAttr($query, $value)
    {
       
        $query->where('project_id', 'in',project::where('project_title', 'like', '%'.$value.'%')->column('project_id'));
    }
    public function searchReservationPersonAttr($query, $value)
    {
        $query->where('reservation_person', 'like', '%'.$value.'%');

    }
   public function searchIdNumberAttr($query, $value)
    {
        $query->where('id_number', 'like', '%'.$value.'%');
        
    }
    public function searchPhoneNumberAttr($query, $value)
    {
        $query->where('phone_number', 'like', '%'.$value.'%');
        
    }
    public function getProjectIdTextAttr($value,$data){
        if(isset($data['project_id'])){
            return  project::where('project_id', $data['project_id'])->value('project_title');
        }
        return '';
    }
    public function getStatusTextAttr($value,$data){
        if(isset($data['status'])){
            if($data['status']==1){
                return '通过';
            }elseif($data['status']==2){
                return '拒绝';
            }else{
                return '待审核';
            }
        }
        return '待审核';
        
    }
    public function getReservationTimeTextAttr($value,$data){
         if(isset($data['reservation_time'])){
          
                return date('Y-m-d H:i',strtotime($data['reservation_time']));
            
         }
         return '';
        
    }

     public function getrentNatureTextAttr($value,$data){
       
        if(isset($data['rent_nature'])){
            return    ClassificationDictionary::where('dictionary_id', $data['rent_nature'])->value('classification_name_zh');
        }
        return '';
    }

}
